package com.scwatch.ext.quartz.system;


import com.scwatch.ext.domain.ScheduleJob;
import org.apache.log4j.Logger;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * 
 * @Description: 若一个方法一次执行不完下次轮转时则等待改方法执行完后才执行下一次操作
 * @author dxm
 * @date 2017年9月19日11:00:49
 */
@DisallowConcurrentExecution
public class QuartzJobFactoryDisallowConcurrentExecution implements Job {
	public final Logger log = Logger.getLogger(this.getClass());

	public void execute(JobExecutionContext context) throws JobExecutionException {
		ScheduleJob scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
		try {
			Thread.sleep(3000);
			TaskUtils.invokMethod(scheduleJob);
		}catch (Exception e){
			JobExecutionException e2 = new JobExecutionException(e);
			// true 表示 Quartz 会自动取消所有与这个 job 有关的 trigger，从而避免再次运行 job
			e2.setUnscheduleAllTriggers(true);
		}
	}
}